<template>
	<view>
		
		<view v-if="isdata">
			<view style="text-align: center;margin-top: 10%;">
				<image :src="user.avatar" class="userAvatar"></image>
			</view>
			<view style="text-align: center;">
				<text style="font-weight: bold; color: #282828;">{{user.nickname}}</text>
			</view>
		</view>
			<div class="coupon-list"  :class="[{disable:disable},{green:data.couponType==3}]"   v-if="isdata">
			  <div class="item acea-row row-center-wrapper" :class="[{green:data.couponType==3}]"  >
			    <div class="money" >
			      <div>
			        ￥<span class="num">{{ data.couponPrice }}</span>
			      </div>
			      <div class="pic-num">满{{ data.useMinPrice }}元可用</div>
			    </div>
			    <div class="text">
			      <div class="condition line1">
			        {{ data.couponTitle }}
			      </div>
			      <div class="data acea-row row-between-wrapper"  >
			     <!--   <div >领卷时间:{{data.createTime}}</div> -->
					 <div >有效时间:{{data.endTime}}</div>
					 <!-- <div>
						<div class="bnt bg-color-red" >点击核销</div>
					 </div> -->
			        
			      </div>
			    </div>
			  </div>
			</div>
			
			<div style="padding: 30rpx;position: fixed;bottom: 0px; width: 100%;"  @click="lq">
				<div style="text-align: center;font-size: 12px;color:  gray;margin-bottom: 10px;">领取后可在 首页-我的-优惠券 中查看</div>
				<button  type="primary">点击领取</button>
				</div>
			
	</view>
</template>

<script>
	import {
		getCouponsUserOneTemp
	} from '@/api/couponqr';
	
	import {
		receive
	} from '@/api/share';

	export default {
		data() {
			return {
				tempId:"",
				data:{},
				user:{},
				isdata:false,
				disable:false,
				power:0,
				type:"",
				
				
			}
		},
		onLoad(e) {
			if (e.id) {
				this.tempId=e.id;
				this.getdata(e.id);

			} else {
				uni.switchTab({
					icon: "error",
					title: "不对劲"
				})
			}
		},
		methods: {
			lq(){
				console.log("领取功能")
				receive(this.tempId).then(e=>{
					this.t('领取成功');
					uni.redirectTo({
						url:'/pages/home/index'
					})
				}).catch(e=>{
					this.t(e.msg)
				})
			},
			getdata(id) {
				let t=this
				getCouponsUserOneTemp(id).then(e=>{
					t.data=e.data.coupon
					t.user=e.data.user
					t.isdata=true
					t.beUsed(t.data)
				})
			},
			beUsed(data){
				let t=new Date(data.endTime).getTime();
				if(data.isFail==0&&data.status==0&&new Date().getTime()<t){
					this.disable=false
				}else{
					this.disable=true
				}
			},
			t(msg){
				uni.showToast({
					title:msg,
					icon:"none"
				})
			}
		},
	
	}
</script>

<style scoped>
	.green{
		filter: hue-rotate(300deg)
	}
	.tips{
		font-size: 14px;
		color: gray;
		text-align: center;
	}
	.coupon-list{
		filter: hue-rotate(225deg);
	}
	.disable{
		filter: grayscale(1);
	}
	.hisList{
		position: fixed;bottom: 20px;
		width: 100%;left: 0;text-align: center;
		color: #277ec1;
		font-size: 14px;
	}
	.userAvatar{
		    width: 100px;
		    height: 100px;
		    border-radius: 50%;
		    border: 6px solid white;
		    box-shadow: 0 0 2px 0px #0000002e;
	}
	.blueBtn{
		background-color: #1890ff;
	}
	.cbody{
		padding: 20px;
	}
	.card{
		padding: 10px;
	}
</style>